package com.example.a2022110541

import android.annotation.SuppressLint
import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
    val expert=ProgramExpert()
    private var textViewCounter = 1
    @SuppressLint("MissingInflatedId", "SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        val addTextViewButton = findViewById<Button>(R.id.add_button)
        val textContainer = findViewById<LinearLayout>(R.id.linear)
        val spinner: Spinner = findViewById(R.id.spinner)
        val button: Button = findViewById(R.id.query_button)
        val textView: TextView = findViewById(R.id.query_result)

        addTextViewButton.setOnClickListener {

            val newTextView = TextView(this)

            newTextView.layoutParams = LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
            )
            newTextView.text = "This is a new textView: $textViewCounter"

            newTextView.textSize = 18f

            textContainer.addView(newTextView)

            textViewCounter++
        }

        button.setOnClickListener {
            textView.text = expert.getLanguageExpert(spinner.selectedItem.toString())
        }
    }
}